package m.store.model;

import m.base.model.GoodsInfo;
import m.base.model.StoreInfo;
import m.common.model.*;
import m.common.model.type.FieldType;
import m.common.model.util.ModelQueryList;
import m.common.model.util.QueryCondition;

import java.util.List;
import java.util.stream.Collectors;

@TableMeta(name="ts_store_goods",description="商户商品")
public class StoreGoods extends GoodsInfo implements MigrationModel {
    @Override
    public List<String> migrationOidList(String storeOid) throws Exception {
        return ModelQueryList.getModelList(this.getClass(),new String[]{"oid"},null,
                        QueryCondition.eq("store.oid",storeOid))
                .stream().map(Model::getOid).collect(Collectors.toList());
    }
    @FieldMeta(name="property",type= FieldType.STRING,description="性质",defaultValue = "A",dictOption = "A:实体,B:服务")
    private String property;
    public final static String Property_Goods="A";
    public final static String Property_Server="B";

    @LinkTableMeta(name="store_oid",table= StoreInfo.class,description="所属商户")
    private StoreInfo store;
    @LinkTableMeta(name="goods_oid",table= GoodsInfo.class,description="引用商品")
    private GoodsInfo goods;
    @FieldMeta(name="offer_price",type= FieldType.DOUBLE,description="报价")
    private Double offerPrice;
    @LinkTableMeta(name="store_type_oid",table= StoreType.class,description="商品分类")
    private StoreType storeType;

    //冗余信息
    @FieldMeta(name="surplus_num",type= FieldType.INT,defaultValue = "0",description="剩余数量|所有库存记录的剩余数量汇总")
    private Integer surplusNum;
    @FieldMeta(name="surplus_amount",type= FieldType.DOUBLE,defaultValue = "0",description="剩余金额|所有库存记录的剩余金额汇总")
    private Double surplusAmount;
    @FieldMeta(name="surplus_price",type= FieldType.DOUBLE,defaultValue = "0",description="剩余均价|剩余金额/剩余数量")
    private Double surplusPrice;
    @FieldMeta(name="stock_num",type= FieldType.INT,defaultValue = "0",description="库存数量|所有库存记录的库存数量汇总")
    private Integer stockNum;
    @FieldMeta(name="stock_amount",type= FieldType.DOUBLE,defaultValue = "0",description="库存金额|所有库存记录的库存金额汇总")
    private Double stockAmount;
    @FieldMeta(name="sale_num",type= FieldType.INT,defaultValue = "0",description="出库数量|所有库存记录的出库金额汇总")
    private Integer saleNum;
    @FieldMeta(name="sale_amount",type= FieldType.DOUBLE,defaultValue = "0",description="出库金额|所有库存记录的出库金额汇总")
    private Double saleAmount;
    @FieldMeta(name="gain_amount",type= FieldType.DOUBLE,defaultValue = "0",description="盈利金额|所有库存的盈利金额汇总")
    private Double gainAmount;

    public StoreType getStoreType() {
        return storeType;
    }

    public void setStoreType(StoreType storeType) {
        this.storeType = storeType;
    }

    public Double getOfferPrice() {
        return offerPrice;
    }

    public void setOfferPrice(Double offerPrice) {
        this.offerPrice = offerPrice;
    }

    public Double getSurplusPrice() {
        return surplusPrice;
    }

    public void setSurplusPrice(Double surplusPrice) {
        this.surplusPrice = surplusPrice;
    }

    public StoreInfo getStore() {
        return store;
    }

    public void setStore(StoreInfo store) {
        this.store = store;
    }

    public GoodsInfo getGoods() {
        return goods;
    }

    public void setGoods(GoodsInfo goods) {
        this.goods = goods;
    }

    public Integer getSurplusNum() {
        return surplusNum;
    }

    public void setSurplusNum(Integer surplusNum) {
        this.surplusNum = surplusNum;
    }

    public Double getSurplusAmount() {
        return surplusAmount;
    }

    public void setSurplusAmount(Double surplusAmount) {
        this.surplusAmount = surplusAmount;
    }

    public Integer getStockNum() {
        return stockNum;
    }

    public void setStockNum(Integer stockNum) {
        this.stockNum = stockNum;
    }

    public Double getStockAmount() {
        return stockAmount;
    }

    public void setStockAmount(Double stockAmount) {
        this.stockAmount = stockAmount;
    }

    public Integer getSaleNum() {
        return saleNum;
    }

    public void setSaleNum(Integer saleNum) {
        this.saleNum = saleNum;
    }

    public Double getSaleAmount() {
        return saleAmount;
    }

    public void setSaleAmount(Double saleAmount) {
        this.saleAmount = saleAmount;
    }

    public Double getGainAmount() {
        return gainAmount;
    }

    public void setGainAmount(Double gainAmount) {
        this.gainAmount = gainAmount;
    }

    public String getProperty() {
        return property;
    }

    public void setProperty(String property) {
        this.property = property;
    }
}
